nums = [1,0,-1,0,-2,2]
target=0
def fourSum(nums,target):
    n=len(nums)
    res=[]
    if n<4:
        return res
    nums.sort()
    for i in range(n-3):
        j=i+1
        while j<n-2:
            c_i,d_i=j+1,n-1
            while c_i<d_i:
                sum_a_b_c_d=nums[i]+nums[j]+nums[c_i]+nums[d_i]
                if sum_a_b_c_d==target:
                    if [nums[i],nums[j],nums[c_i],nums[d_i]] not in res:
                        res.append([nums[i],nums[j],nums[c_i],nums[d_i]])
                    c_i+=1
                    d_i-=1
                elif sum_a_b_c_d>target:
                    d_i-=1
                else:
                    c_i+=1
            j+=1
    return res

print(fourSum(nums,target))